package net.jescort.domain.forum;

import java.util.Calendar;
import java.util.Map;
import java.util.Set;

import net.gelif.kernel.core.domain.AbstractPersistable;
import net.jescort.domain.enumerator.TopicStatus;
import net.jescort.domain.user.User;
import org.apache.commons.lang.builder.CompareToBuilder;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

public class Topic extends AbstractPersistable<Integer> implements Comparable<Topic>
{
    private static final long serialVersionUID = 5166485833227363406L;
    
    public Topic()
    {
    }
    
    public Topic(Integer id)
    {
        this.id = id;
    }
    
    private Integer id;
    private String subject;
    private String content;
    private Integer forumId;
    private User poster;
    private int views;
    private int replies;
    private Calendar editdate;
    private Map<TopicStatus, Boolean> status;
    private Set<Tag> tags;
    private Map<String, String> properties;
    
    public Integer getId()
    {
        return id;
    }
    public void setId(Integer id)
    {
        this.id = id;
    }

    public String getSubject()
    {
        return subject;
    }
    public void setSubject(String subject)
    {
        this.subject = subject;
    }

    public String getContent()
    {
        return content;
    }
    public void setContent(String content)
    {
        this.content = content;
    }
    
    public Integer getForumId()
    {
        return forumId;
    }
    public void setForumId(Integer forumId)
    {
        this.forumId = forumId;
    }
    
    public User getPoster()
    {
        return poster;
    }
    public void setPoster(User poster)
    {
        this.poster = poster;
    }
    
    public Calendar getEditdate()
    {
        return editdate;
    }
    public void setEditdate(Calendar editdate)
    {
        this.editdate = editdate;
    }
    
    public int getViews()
    {
        return views;
    }
    public void setViews(int views)
    {
        this.views = views;
    }

    public int getReplies()
    {
        return replies;
    }
    public void setReplies(int replies)
    {
        this.replies = replies;
    }

    public Set<Tag> getTags()
    {
        return tags;
    }
    public void setTags(Set<Tag> tags)
    {
        this.tags = tags;
    }

    public Map<TopicStatus, Boolean> getStatus()
    {
        return status;
    }
    public void setStatus(Map<TopicStatus, Boolean> status)
    {
        this.status = status;
    }
    
    public Map<String, String> getProperties()
    {
        return properties;
    }
    public void setProperties(Map<String, String> properties)
    {
        this.properties = properties;
    }
    
    @Override
    public boolean equals(Object object)
    {
        if(this == object)
        {
            return true;
        }
        if(!(object instanceof Topic))
        {
            return false;
        }
        final Topic topic = (Topic)object;
        return new EqualsBuilder().append(id, topic.getId()).isEquals();
    }
    
    @Override
    public int hashCode()
    {
        return new HashCodeBuilder().append(id).toHashCode();
    }
    
    @Override
    public String toString()
    {
        return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).append("id", this.id).append("subject", this.subject).append("poster", null != this.poster ? (null != this.poster.getUsername() ? this.poster.getUsername() : this.poster.getId()) : null).append("views", this.views).append("replies", this.replies).toString();
    }
    
    public int compareTo(Topic topic)
    {
        return new CompareToBuilder().append(getViews(), topic.getViews()).toComparison();
    }
}
